package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysRetail;
import com.ruoyi.system.service.ISysRetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRetailProduct;
import com.ruoyi.system.service.ISysRetailProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 散户商品管理Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/system/retailProduct")
public class SysRetailProductController extends BaseController
{
    @Autowired
    private ISysRetailProductService sysRetailProductService;
    @Autowired
    private ISysRetailService sysRetailService;

    /**
     * 查询散户商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:retailProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRetailProduct sysRetailProduct)
    {
        startPage();
        List<SysRetailProduct> list = sysRetailProductService.selectSysRetailProductList(sysRetailProduct);
        return getDataTable(list);
    }

    /**
     * 导出散户商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:retailProduct:export')")
    @Log(title = "散户商品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRetailProduct sysRetailProduct)
    {
        List<SysRetailProduct> list = sysRetailProductService.selectSysRetailProductList(sysRetailProduct);
        ExcelUtil<SysRetailProduct> util = new ExcelUtil<SysRetailProduct>(SysRetailProduct.class);
        util.exportExcel(response, list, "散户商品管理数据");
    }

    /**
     * 获取散户商品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:retailProduct:query')")
    @GetMapping("/getInfo")
    public AjaxResult getInfo(@RequestParam("rId") Long rId, @RequestParam("pId") Long proId)
    {
        return success(sysRetailProductService.selectSysRetailProductByRId(rId,proId));
    }

    /**
     * 新增散户商品管理
     */
    @PreAuthorize("@ss.hasPermi('system:retailProduct:add')")
    @Log(title = "散户商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRetailProduct sysRetailProduct)
    {
        return toAjax(sysRetailProductService.insertSysRetailProduct(sysRetailProduct));
    }

    /**
     * 修改散户商品管理
     */
    @PreAuthorize("@ss.hasPermi('system:retailProduct:edit')")
    @Log(title = "散户商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRetailProduct sysRetailProduct)
    {
        return toAjax(sysRetailProductService.updateSysRetailProduct(sysRetailProduct));
    }

    /**
     * 删除散户商品管理
     */
    @PreAuthorize("@ss.hasPermi('system:retailProduct:remove')")
    @Log(title = "散户商品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rIds}")
    public AjaxResult remove(@PathVariable Long[] rIds)
    {
        return toAjax(sysRetailProductService.deleteSysRetailProductByRIds(rIds));
    }

}
